package com.jellyfishumbrella.GL;

import static org.lwjgl.opengl.GL11.*;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.util.vector.Vector3f;

public class Sun extends AnimObject {
	private static FloatBuffer	tempBuffer	= BufferUtils.createFloatBuffer(4);
	private float distance = 1000;
	private float angle = 0;

	public Sun() {
		super();
	}

	public void addSun(float[] ambColor, float[] diffColor, float[] specColor) {
		keyframes.here.pos = new Vector3d(0.0f, 1.0f, 0.0f);
		loadTempBuffer(ambColor);
		glLight(GL_LIGHT0, GL_AMBIENT, tempBuffer);
		loadTempBuffer(diffColor);
		glLight(GL_LIGHT0, GL_DIFFUSE, tempBuffer);
		loadTempBuffer(specColor);
		glLight(GL_LIGHT0, GL_SPECULAR, tempBuffer);
		loadTempBuffer(new float[] { keyframes.here.pos.toGL().x, keyframes.here.pos.toGL().y, keyframes.here.pos.toGL().z, 1.0f });
		glLight(GL_LIGHT0, GL_POSITION, tempBuffer);
		glEnable(GL_LIGHT0);
	}

	private void loadTempBuffer(float[] data) {
		tempBuffer.rewind();
		tempBuffer.put(data);
		tempBuffer.flip();
	}

	public void render() {
		//angle += .001f % 360.0f;
		angle = -65;
		keyframes.here.pos.x = (float) (distance * Math.cos(angle));
		keyframes.here.pos.y = (float) (distance * Math.sin(angle));
		
//		glPushMatrix();
		loadTempBuffer(new float[] { keyframes.here.pos.toGL().x, keyframes.here.pos.toGL().y, keyframes.here.pos.toGL().z, 0.0f });
		glLight(GL_LIGHT0, GL_POSITION, tempBuffer);
//		glPopMatrix();
	}
}
